package testproject;

import DAO.*;
import java.sql.Date;
import java.util.Vector;
import javax.swing.JOptionPane;

public class InsertVacFillDetail extends javax.swing.JFrame {

    VacFillDetailDAO vacFillDao = new VacFillDetailDAO();

    public InsertVacFillDetail() {
        initComponents();
        
        lblVacFillVacIdCheck.setVisible(false);
        lblVacFillEmpIdCheck.setVisible(false);
        lblVacFillDateCheck.setVisible(false);
        lblVacFillInDetailsCheck.setVisible(false);

        vacFillDao.loadVacFillCombobox(cbVacFillVacId, cbVacFillEmpId);
    }

    public boolean validateVacFillInsert() {
        if (cbVacFillVacId.getSelectedIndex() == 0) {
            lblVacFillVacIdCheck.setVisible(true);
            cbVacFillVacId.requestFocus();
            return false;
        }
        lblVacFillVacIdCheck.setVisible(false);
        if (cbVacFillEmpId.getSelectedIndex() == 0) {
            lblVacFillEmpIdCheck.setVisible(true);
            cbVacFillEmpId.requestFocus();
            return false;
        }
        lblVacFillEmpIdCheck.setVisible(false);
        if (txtVacFillDate.getText().equals("")) {
            lblVacFillDateCheck.setVisible(true);
            txtVacFillDate.requestFocus();
            return false;
        }
        lblVacFillDateCheck.setVisible(false);
        if (txaVacFillInDetail.getText().equals("")) {
            lblVacFillInDetailsCheck.setVisible(true);
            txaVacFillInDetail.requestFocus();
            return false;
        }
        lblVacFillInDetailsCheck.setVisible(false);
        return true;
    }

    public void resetVacFillInsert() {
        cbVacFillVacId.setSelectedIndex(0);
        cbVacFillEmpId.setSelectedIndex(0);
        txtVacFillDate.setText("");
        txaVacFillInDetail.setText("");

    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel6 = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        lblVacFillVacIdCheck = new javax.swing.JLabel();
        lblVacFillEmpIdCheck = new javax.swing.JLabel();
        lblVacFillDateCheck = new javax.swing.JLabel();
        lblVacFillInDetailsCheck = new javax.swing.JLabel();
        cbVacFillVacId = new javax.swing.JComboBox();
        cbVacFillEmpId = new javax.swing.JComboBox();
        jScrollPane1 = new javax.swing.JScrollPane();
        txaVacFillInDetail = new javax.swing.JTextArea();
        btnVacFillInsert = new javax.swing.JButton();
        btnVacFillReset = new javax.swing.JButton();
        btnVacFillCancel = new javax.swing.JButton();
        txtVacFillDate = new javax.swing.JTextField();

        jLabel6.setText("jLabel6");

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N
        jLabel1.setForeground(new java.awt.Color(102, 102, 255));
        jLabel1.setText("Vacancy Filling Information");

        jLabel2.setForeground(new java.awt.Color(102, 102, 255));
        jLabel2.setText("Vacancy ID:");

        jLabel3.setForeground(new java.awt.Color(102, 102, 255));
        jLabel3.setText("Employee ID:");

        jLabel4.setForeground(new java.awt.Color(102, 102, 255));
        jLabel4.setText("Fill Date:");

        jLabel5.setForeground(new java.awt.Color(102, 102, 255));
        jLabel5.setText("Intake Details:");

        lblVacFillVacIdCheck.setForeground(new java.awt.Color(255, 0, 0));
        lblVacFillVacIdCheck.setText("Need To choice one Vacancy ID");

        lblVacFillEmpIdCheck.setForeground(new java.awt.Color(255, 0, 0));
        lblVacFillEmpIdCheck.setText("Need To choice Employee ID");

        lblVacFillDateCheck.setForeground(new java.awt.Color(255, 0, 0));
        lblVacFillDateCheck.setText("Fill Date Cannot be blank");

        lblVacFillInDetailsCheck.setForeground(new java.awt.Color(255, 0, 0));
        lblVacFillInDetailsCheck.setText("Intake Details Cannot be blank");

        cbVacFillVacId.setForeground(new java.awt.Color(102, 102, 255));
        cbVacFillVacId.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));

        cbVacFillEmpId.setForeground(new java.awt.Color(102, 102, 255));
        cbVacFillEmpId.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));

        txaVacFillInDetail.setColumns(20);
        txaVacFillInDetail.setForeground(new java.awt.Color(102, 102, 255));
        txaVacFillInDetail.setRows(5);
        jScrollPane1.setViewportView(txaVacFillInDetail);

        btnVacFillInsert.setForeground(new java.awt.Color(102, 102, 255));
        btnVacFillInsert.setText("Insert");
        btnVacFillInsert.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnVacFillInsertActionPerformed(evt);
            }
        });

        btnVacFillReset.setForeground(new java.awt.Color(102, 102, 255));
        btnVacFillReset.setText("Reset");
        btnVacFillReset.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnVacFillResetActionPerformed(evt);
            }
        });

        btnVacFillCancel.setForeground(new java.awt.Color(102, 102, 255));
        btnVacFillCancel.setText("Cancel");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(78, 78, 78)
                        .addComponent(jLabel1))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(33, 33, 33)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel3)
                                    .addComponent(jLabel4))
                                .addGap(45, 45, 45)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                        .addComponent(cbVacFillEmpId, 0, 200, Short.MAX_VALUE)
                                        .addComponent(lblVacFillEmpIdCheck, javax.swing.GroupLayout.DEFAULT_SIZE, 200, Short.MAX_VALUE))
                                    .addComponent(txtVacFillDate, javax.swing.GroupLayout.PREFERRED_SIZE, 200, javax.swing.GroupLayout.PREFERRED_SIZE)))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabel2)
                                .addGap(51, 51, 51)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(lblVacFillVacIdCheck, javax.swing.GroupLayout.DEFAULT_SIZE, 200, Short.MAX_VALUE)
                                    .addComponent(cbVacFillVacId, 0, 200, Short.MAX_VALUE)))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabel5)
                                .addGap(39, 39, 39)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(lblVacFillInDetailsCheck, javax.swing.GroupLayout.DEFAULT_SIZE, 200, Short.MAX_VALUE)
                                    .addComponent(lblVacFillDateCheck, javax.swing.GroupLayout.DEFAULT_SIZE, 200, Short.MAX_VALUE)
                                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 200, Short.MAX_VALUE))))
                        .addGap(70, 70, 70)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(btnVacFillCancel, javax.swing.GroupLayout.PREFERRED_SIZE, 70, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(btnVacFillReset, javax.swing.GroupLayout.PREFERRED_SIZE, 70, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(btnVacFillInsert, javax.swing.GroupLayout.PREFERRED_SIZE, 70, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addContainerGap(52, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(23, 23, 23)
                .addComponent(jLabel1)
                .addGap(31, 31, 31)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel2)
                            .addComponent(cbVacFillVacId, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addComponent(lblVacFillVacIdCheck)
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel3)
                            .addComponent(cbVacFillEmpId, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addComponent(lblVacFillEmpIdCheck)
                        .addGap(21, 21, 21)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel4)
                            .addComponent(txtVacFillDate, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addComponent(lblVacFillDateCheck)
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel5)
                            .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(1, 1, 1)
                        .addComponent(btnVacFillInsert)
                        .addGap(50, 50, 50)
                        .addComponent(btnVacFillReset)
                        .addGap(50, 50, 50)
                        .addComponent(btnVacFillCancel)))
                .addGap(18, 18, 18)
                .addComponent(lblVacFillInDetailsCheck)
                .addContainerGap(47, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnVacFillInsertActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnVacFillInsertActionPerformed
        if (validateVacFillInsert()) {

            String VacID = cbVacFillVacId.getSelectedItem().toString().trim();
            String EmpID = cbVacFillEmpId.getSelectedItem().toString().trim();
            String FillDate = txtVacFillDate.getText().trim();
            String IntakeDetail = txaVacFillInDetail.getText().trim();

            Vector v = new Vector();
            v.add(VacID);
            v.add(EmpID);
            v.add(FillDate);
            v.add(IntakeDetail);

            if (!validateVacFillInsert()) {
                return;
            }

            if (!vacFillDao.insertVacFill(v)) {
                JOptionPane.showMessageDialog(this, "Cannot Insert! Please try again!", "INSERT VACANCIES Fill Detail", JOptionPane.ERROR_MESSAGE);
                return;
            }
            JOptionPane.showMessageDialog(this, "Insert new VACANCIES successfully!", "INSERT VACANCIES Fill Detail", JOptionPane.INFORMATION_MESSAGE);
        }
    }//GEN-LAST:event_btnVacFillInsertActionPerformed

    private void btnVacFillResetActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnVacFillResetActionPerformed
        resetVacFillInsert();
    }//GEN-LAST:event_btnVacFillResetActionPerformed

    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(InsertVacFillDetail.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(InsertVacFillDetail.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(InsertVacFillDetail.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(InsertVacFillDetail.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new InsertVacFillDetail().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnVacFillCancel;
    private javax.swing.JButton btnVacFillInsert;
    private javax.swing.JButton btnVacFillReset;
    private javax.swing.JComboBox cbVacFillEmpId;
    private javax.swing.JComboBox cbVacFillVacId;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JLabel lblVacFillDateCheck;
    private javax.swing.JLabel lblVacFillEmpIdCheck;
    private javax.swing.JLabel lblVacFillInDetailsCheck;
    private javax.swing.JLabel lblVacFillVacIdCheck;
    private javax.swing.JTextArea txaVacFillInDetail;
    private javax.swing.JTextField txtVacFillDate;
    // End of variables declaration//GEN-END:variables
}
